package com.knowledgegraph.zhongyao.service.impl;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.knowledgegraph.common.utils.DateUtils;
import com.knowledgegraph.neo4j.domain.GraphNode;
import com.knowledgegraph.neo4j.mapper.GraphNodeMapper;
import com.knowledgegraph.neo4j.mapper.Neo4jNodeMapper;
import com.knowledgegraph.neo4j.service.INeo4jNodeService;
import com.knowledgegraph.neo4j.service.impl.GraphNodeServiceImpl;
import com.knowledgegraph.neo4j.service.impl.Neo4jNodeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.knowledgegraph.zhongyao.mapper.PrescriptionMapper;
import com.knowledgegraph.zhongyao.domain.Prescription;
import com.knowledgegraph.zhongyao.service.IPrescriptionService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 方剂维护Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-07-03
 */
@Service
public class PrescriptionServiceImpl implements IPrescriptionService 
{
    @Autowired
    private PrescriptionMapper prescriptionMapper;

    @Autowired
    private INeo4jNodeService neo4jNodeMapper;

    @Autowired
    private GraphNodeMapper graphNodeMapper;
    /**
     * 查询方剂维护
     * 
     * @param prescriptionKey 方剂维护主键
     * @return 方剂维护
     */
    @Override
    public Prescription selectPrescriptionByPrescriptionKey(String prescriptionKey)
    {
        return prescriptionMapper.selectPrescriptionByPrescriptionKey(prescriptionKey);
    }

    /**
     * 查询方剂维护列表
     * 
     * @param prescription 方剂维护
     * @return 方剂维护
     */
    @Override
    public List<Prescription> selectPrescriptionList(Prescription prescription)
    {
        return prescriptionMapper.selectPrescriptionList(prescription);
    }

    /**
     * 新增方剂维护
     * 
     * @param prescription 方剂维护
     * @return 结果
     */
    @Override
    @Transactional
    public int insertPrescription(Prescription prescription, GraphNode graphNode )
    {

        prescription.setCreateTime(DateUtils.getNowDate());

        graphNodeMapper.insertGraphNode(graphNode);

        return prescriptionMapper.insertPrescription(prescription);
    }

    /**
     * 修改方剂维护
     * 
     * @param prescription 方剂维护
     * @return 结果
     */
    @Override
    @Transactional
    public int updatePrescription(Prescription prescription, GraphNode graphNode )
    {
        prescription.setCreateTime(DateUtils.getNowDate());
        prescription.setUpdateTime(DateUtils.getNowDate());
        graphNodeMapper.updateGraphNode(graphNode);
        return prescriptionMapper.updatePrescription(prescription);
    }

    /**
     * 批量删除方剂维护
     * 
     * @param prescriptionKeys 需要删除的方剂维护主键
     * @return 结果
     */
    @Override
    public int deletePrescriptionByPrescriptionKeys(String[] prescriptionKeys)
    {
        return prescriptionMapper.deletePrescriptionByPrescriptionKeys(prescriptionKeys);
    }

    /**
     * 删除方剂维护信息
     * 
     * @param prescriptionKey 方剂维护主键
     * @return 结果
     */
    @Override
    public int deletePrescriptionByPrescriptionKey(String prescriptionKey)
    {
        return prescriptionMapper.deletePrescriptionByPrescriptionKey(prescriptionKey);
    }

    @Override
    public Long getid(String prescriptionKey) {
        return prescriptionMapper.getid(prescriptionKey);
    }
}
